package com.future.direction.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.future.direction.R;
import com.future.direction.common.util.PopuUtil;
import com.future.direction.data.bean.BankCardListBean;
import com.future.direction.di.component.AppComponent;
import com.future.direction.ui.adapter.BankCardListAdapter;
import com.future.direction.ui.widget.MyPopupWindow;
import com.future.direction.ui.widget.MyTitleBar;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 绑定银行卡列表
 */
public class BankCardListActivity extends BaseActivity implements View.OnClickListener {


    @BindView(R.id.titleBar)
    MyTitleBar titleBar;
    @BindView(R.id.rl_add_bank_card)
    RelativeLayout rlAddBankCard;
    @BindView(R.id.recycler_bank_card)
    RecyclerView recyclerBankCard;
    @BindView(R.id.ll_bank_card)
    LinearLayout llBankCard;
    private BankCardListAdapter bankCardListAdapter;

    @Override
    public int setLayout() {
        return R.layout.activity_bank_card_list;
    }

    @Override
    public void getExtras() {

    }

    @Override
    public boolean init() {
        initRecycler();
        return false;
    }

    private void initRecycler() {
        LinearLayoutManager manager = new LinearLayoutManager(this);
        recyclerBankCard.setLayoutManager(manager);
        List<BankCardListBean> data = new ArrayList<>();
        for (int i = 0; i < 2; i++) {
            BankCardListBean bankCardListBean = new BankCardListBean();
            data.add(bankCardListBean);
        }
        bankCardListAdapter = new BankCardListAdapter(R.layout.item_bank_card_list, data);
        recyclerBankCard.setAdapter(bankCardListAdapter);
    }

    @Override
    public void setListener() {
        backListener(titleBar);
        rlAddBankCard.setOnClickListener(this);

        bankCardListAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                switch (view.getId()) {
                    case R.id.iv_delete_bank_card:
                        unbundleBankCard();
                        break;
                }
            }
        });
    }

    private void unbundleBankCard() {
        MyPopupWindow unbundleBankCardPopupWindow = new PopuUtil().initAtLocationPopuWrap(this,
                R.layout.popup_exit, llBankCard, 265, 110);
        TextView tvTitle = unbundleBankCardPopupWindow.getContentView().findViewById(R.id.tv_title);
        Button buttonPopupCancel = unbundleBankCardPopupWindow.getContentView().findViewById(R.id.button_creat_cancel);
        Button buttonPopupCommitSure = unbundleBankCardPopupWindow.getContentView().findViewById(R.id.button_creat_commit_sure);
        tvTitle.setText("确定解绑当前银行卡?");
        buttonPopupCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                unbundleBankCardPopupWindow.dismiss();
            }
        });
        buttonPopupCommitSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                unbundleBankCardPopupWindow.dismiss();
                //解绑
            }
        });
    }

    @Override
    public void setupAcitivtyComponent(AppComponent appComponent) {

    }


    @Override
    public void onClick(View v) {
        Intent intent = new Intent(BankCardListActivity.this, BindingBankCardFristActivity.class);
        startActivity(intent);
    }

}
